/*******************************************************************

    Author: Xiao
    Date: 2022/3/28 10:12

*******************************************************************/

package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type config struct {
	Debug           bool     `yaml:"debug"`
	ServiceName     string   `yaml:"serviceName"`
	ListenAddr      string   `yaml:"listenAddr"`
	JwtExpire       int      `yaml:"jwtExpire"`
	StorePath       string   `yaml:"storePath"`
	FrontendUrl     string   `yaml:"frontendUrl"`
	TencentAiAppid  string   `yaml:"tencentAiAppid"`
	TencentAiAppkey string   `yaml:"tencentAiAppkey"`
	TencentAiToken  string   `yaml:"tencentAiToken"`
	AesKey          string   `yaml:"aesKey"`
	GuestToken      string   `yaml:"guestToken"`
	SimpleRegister  bool     `yaml:"simpleRegister"`
	MDBConfig       *MysqlDb `yaml:"mysqlDb"`
	RDBConfig       *RedisDb `yaml:"redisDb"`
	Mail            *mail    `yaml:"mail"`
}

type MysqlDb struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Name     string `yaml:"name"`
}

type RedisDb struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
	Select   int    `yaml:"select"`
}

type mail struct {
	Host     string   `yaml:"host"`
	Port     int      `yaml:"port"`
	User     string   `yaml:"user"`
	Password string   `yaml:"password"`
	Nickname string   `yaml:"nickname"`
	Sendobjs []string `yaml:"sendobjs"`
}

var (
	ConfigValue = new(config)
)

func init() {
	// 解析配置文件
	yamlFile, err := ioutil.ReadFile("config.yaml")
	if err != nil {
		log.Fatalln(err)
	}
	err = yaml.Unmarshal(yamlFile, ConfigValue)
	if err != nil {
		log.Fatalln(err)
	}
}
